package com.zz.inventory.domain;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@NoArgsConstructor
public class ServiceResult<T> {
    private boolean success;
    private String errorMsg;
    private T data;

    // 正确的构造方法
    private ServiceResult(boolean success, String errorMsg, T data) {
        this.success = success;
        this.errorMsg = errorMsg;
        this.data = data;
    }

    public static <T> ServiceResult<T> success(T data) {
        return new ServiceResult<>(true, null, data);
    }

    public static <T> ServiceResult<T> fail(String errorMsg) {
        return new ServiceResult<>(false, errorMsg, null);
    }
}